<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow = !isShow">{{isShow?'隐藏':'显示'}}</button>
    <home v-if="isShow"></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    
    const Home = {
      template: `
        <div>
          <h2>这是一个组件</h2>  
          <button @click="addLi">增加一个li</button>
          <ul ref='oul'>
            <li v-for="item in arr" :key="item">
              {{item}}  
            </li>  
          </ul>
        </div>
      `,
      data(){
        return {
          arr: [1,2,3]
        }
      },
      methods: {
        addLi(){
          this.arr.push(this.arr.length+1);
          this.$nextTick(()=> {
            console.log('nextTick');
          })
        }
      },
      beforeCreate(){
        console.log('beforeCreate');
      },
      created(){
        console.log('created');
      },
      beforeMount(){
        console.log('beforeMount');
      },
      mounted(){
        console.log('mounted');
      },
      beforeUpdate(){
        console.log('更新之前');
      },
      updated(){
        console.log('数据改变视图已经更新-updated');
      },
      beforeDestroy(){
        console.log('组件卸载之前');
      },
      destroyed(){
        console.log('组件已经卸载');
      }
    }

    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>